package com.youth.youthservice.controller;

import com.baomidou.mybatisplus.extension.api.ApiController;
import com.youth.commonutils.R;
import com.youth.youthservice.service.EduCourseCollectService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 课程收藏(EduCourseCollect)表控制层
 *
 * @author CM
 * @since 2023-05-05 13:08:01
 */
@RestController
@RequestMapping("/eduservice/course/collect")
public class EduCourseCollectController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private EduCourseCollectService eduCourseCollectService;

    /**
     * 用户登陆后检查课程是否已经被收藏
     *
     * @param courseId
     * @return
     */
    @GetMapping("{id}")
    public R checkCollect(@PathVariable("id") String courseId, HttpServletRequest request) {
        return eduCourseCollectService.checkCollect(courseId, request);
    }

    /*用户登录后收藏课程*/
    @PostMapping("{id}")
    public R collect(@PathVariable("id") String courseId, HttpServletRequest request) {
        return eduCourseCollectService.collect(courseId, request);
    }

    /*个人中心查询我的收藏*/
    @GetMapping("/{pageNum}/{pageSize}")
    public R collectCourseList(@PathVariable("pageNum") Long pageNum, @PathVariable("pageSize") Long pageSize
            , HttpServletRequest request) {
        return eduCourseCollectService.listByUserId(pageNum, pageSize, request);
    }

    /*取消收藏课程*/
    @DeleteMapping("{id}")
    public R cancelCollect(@PathVariable("id") String id) {
        return eduCourseCollectService.cancel(id);
    }

    /*设置置顶*/
    @PutMapping("{id}")
    public R setTop(@PathVariable("id") String id){
        return eduCourseCollectService.setTop(id);
    }
}

